package com.goldmantis.ssm.service;

import com.goldmantis.ssm.bean.SysUser;
import com.goldmantis.ssm.bean.SysUserExample;
import com.goldmantis.ssm.dao.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    public List<SysUser> get(){
        return sysUserMapper.selectByExample(null);
    }

    public int insert(SysUser sysUser)  {
         return sysUserMapper.insertSelective(sysUser);
    }


    public int update(SysUser sysUser) {

        return sysUserMapper.updateByPrimaryKeySelective(sysUser);
    }

    public Boolean CheckUser(){
        SysUserExample sysUserExample=new SysUserExample();
        SysUserExample.Criteria criteria = sysUserExample.createCriteria();
        criteria.andAccountEqualTo("chenjindong");

        long count = sysUserMapper.countByExample(sysUserExample);
        return count>0;
    }

    public void delete(Integer id) {
        sysUserMapper.deleteByPrimaryKey(id);
    }

    public int deleteBatch(List<Integer> ids){
        SysUserExample sysUserExample=new SysUserExample();
        SysUserExample.Criteria sysUserExampleCriteria = sysUserExample.createCriteria();
        sysUserExampleCriteria.andUserIdIn(ids);

        return sysUserMapper.deleteByExample(sysUserExample);
    }
}
